﻿Imports System.Data.SqlClient

Public Class clsE_Incentivos
    Private mintIdIncentivo As Integer
    Private mintIdAutobus As Integer
    Private mstrNoEconomico As String
    Private mintIdOperador As Integer
    Private mstrNombreOperador As String
    Private mdblDia1 As Double
    Private mdblDia2 As Double
    Private mdblDia3 As Double
    Private mdblDia4 As Double
    Private mdblDia5 As Double
    Private mdblDia6 As Double
    Private mdblDia7 As Double
    Private mdblAcumulado As Double
    Private mdatFechaInicial As Date
    Private mdatFechaFinal As Date
    Public Property IdIncentivo() As Integer
        Get
            Return mintIdIncentivo
        End Get
        Set(ByVal value As Integer)
            mintIdIncentivo = value
        End Set
    End Property
    Public Property IdAutobus() As Integer
        Get
            Return mintIdAutobus
        End Get
        Set(ByVal value As Integer)
            mintIdAutobus = value
        End Set
    End Property

    Public Property NoEconomico() As String
        Get
            Return mstrNoEconomico
        End Get
        Set(ByVal value As String)
            mstrNoEconomico = value
        End Set
    End Property
    Public Property IdOperador() As Integer
        Get
            Return mintIdOperador
        End Get
        Set(ByVal value As Integer)
            mintIdOperador = value
        End Set
    End Property
    Public Property NombreOperador() As String
        Get
            Return mstrNombreOperador
        End Get
        Set(ByVal value As String)
            mstrNombreOperador = value
        End Set
    End Property
    Public Property Dia1() As Double
        Get
            Return mdblDia1
        End Get
        Set(ByVal value As Double)
            mdblDia1 = value
        End Set
    End Property
    Public Property Dia2() As Double
        Get
            Return mdblDia2
        End Get
        Set(ByVal value As Double)
            mdblDia2 = value
        End Set
    End Property
    Public Property Dia3() As Double
        Get
            Return mdblDia3
        End Get
        Set(ByVal value As Double)
            mdblDia3 = value
        End Set
    End Property
    Public Property Dia4() As Double
        Get
            Return mdblDia4
        End Get
        Set(ByVal value As Double)
            mdblDia4 = value
        End Set
    End Property
    Public Property Dia5() As Double
        Get
            Return mdblDia5
        End Get
        Set(ByVal value As Double)
            mdblDia5 = value
        End Set
    End Property
    Public Property Dia6() As Double
        Get
            Return mdblDia6
        End Get
        Set(ByVal value As Double)
            mdblDia6 = value
        End Set
    End Property
    Public Property Dia7() As Double
        Get
            Return mdblDia7
        End Get
        Set(ByVal value As Double)
            mdblDia7 = value
        End Set
    End Property
    Public Property Acumulado() As Double
        Get
            Return mdblAcumulado
        End Get
        Set(ByVal value As Double)
            mdblAcumulado = value
        End Set
    End Property
    Public Property FechaInicial() As Date
        Get
            Return mdatFechaInicial
        End Get
        Set(ByVal value As Date)
            mdatFechaInicial = value
        End Set
    End Property
    Public Property FechaFinal() As Date
        Get
            Return mdatFechaFinal
        End Get
        Set(ByVal value As Date)
            mdatFechaFinal = value
        End Set
    End Property
    Public Sub New()
        mintIdIncentivo = 0
        mintIdAutobus = 0
        mstrNoEconomico = ""
        mintIdOperador = 0
        mstrNombreOperador = ""
        mdblDia1 = 0
        mdblDia2 = 0
        mdblDia3 = 0
        mdblDia4 = 0
        mdblDia5 = 0
        mdblDia6 = 0
        mdblDia7 = 0
        mdblAcumulado = 0
        mdatFechaInicial = Now()
        mdatFechaFinal = Now()
    End Sub
    Public Sub Insertar()
        Dim sql As String = "Insert Into E_Incentivos (" & _
                            "IdAutobus," & _
                            "NoEconomico," & _
                            "IdOperador," & _
                            "NombreOperador," & _
                            "Dia1," & _
                            "Dia2," & _
                            "Dia3," & _
                            "Dia4," & _
                            "Dia5," & _
                            "Dia6," & _
                            "Dia7," & _
                            "Acumulado," & _
                            "FechaInicial," & _
                            "FechaFinal) " & _
                            "VALUES (" & _
                            "@IdAutobus," & _
                            "substring(@NoEconomico,1,100)," & _
                            "@IdOperador," & _
                            "substring(@NombreOperador,1,150)," & _
                            "@Dia1," & _
                            "@Dia2," & _
                            "@Dia3," & _
                            "@Dia4," & _
                            "@Dia5," & _
                            "@Dia6," & _
                            "@Dia7," & _
                            "@Acumulado," & _
                            "@FechaInicial," & _
                            "@FechaFinal) "

        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim Command As New SqlCommand(sql, cnConn)

        Command.Parameters.AddWithValue("IdAutobus", mintIdAutobus)
        Command.Parameters.AddWithValue("NoEconomico", mstrNoEconomico)
        Command.Parameters.AddWithValue("IdOperador", mintIdOperador)
        Command.Parameters.AddWithValue("NombreOperador", mstrNombreOperador)
        Command.Parameters.AddWithValue("Dia1", mdblDia1)
        Command.Parameters.AddWithValue("Dia2", mdblDia2)
        Command.Parameters.AddWithValue("Dia3", mdblDia3)
        Command.Parameters.AddWithValue("Dia4", mdblDia4)
        Command.Parameters.AddWithValue("Dia5", mdblDia5)
        Command.Parameters.AddWithValue("Dia6", mdblDia6)
        Command.Parameters.AddWithValue("Dia7", mdblDia7)
        Command.Parameters.AddWithValue("Acumulado", mdblAcumulado)
        Command.Parameters.AddWithValue("FechaInicial", mdatFechaInicial)
        Command.Parameters.AddWithValue("FechaFinal", mdatFechaFinal)

        cnConn.Open()
        Dim RowsAffected As Integer
        Try
            RowsAffected = Command.ExecuteNonQuery
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Aviso")
        End Try

        If RowsAffected > 0 Then
            cnConn.Close()
        Else
            MsgBox("No fue posible insertar el registro de incentivos", MsgBoxStyle.Exclamation, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End If
    End Sub
   
End Class
